{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Inspect Data"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "This example shows how to inspect the data of a loaded test system."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [],
   "source": [
    "import andes\n",
    "from andes.utils.paths import get_case"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "To show all the rows and columns, change the pandas configuration with"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "\n",
    "pd.options.display.max_columns = None\n",
    "pd.options.display.max_rows = None"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Let's load the Kundur's system."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "Parsing input file </Users/hcui7/repos/andes/cases/kundur/kundur_full.xlsx>\n",
      "Input file kundur_full.xlsx parsed in 0.4202 second.\n",
      "-> Power flow calculation with Newton Raphson method:\n",
      "Power flow initialized.\n",
      "0: |F(x)| = 14.9283   \n",
      "1: |F(x)| = 3.60859   \n",
      "2: |F(x)| = 0.170093  \n",
      "3: |F(x)| = 0.00203827\n",
      "4: |F(x)| = 3.76414e-07\n",
      "Converged in 5 iterations in 0.0138 second.\n",
      "Report saved to </Users/hcui7/notebooks/examples/kundur_full_out.txt> in 0.0011 second.\n",
      "-> Single process finished in 0.6818 second.\n"
     ]
    }
   ],
   "source": [
    "ss = andes.run(get_case('kundur/kundur_full.xlsx'))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Parameters"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Parameters from the input file are stored in `cache.df_in` of the model. For `GENROU`, do"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>idx</th>\n",
       "      <th>u</th>\n",
       "      <th>name</th>\n",
       "      <th>bus</th>\n",
       "      <th>gen</th>\n",
       "      <th>coi</th>\n",
       "      <th>Sn</th>\n",
       "      <th>Vn</th>\n",
       "      <th>fn</th>\n",
       "      <th>D</th>\n",
       "      <th>...</th>\n",
       "      <th>S12</th>\n",
       "      <th>xd</th>\n",
       "      <th>xd1</th>\n",
       "      <th>xd2</th>\n",
       "      <th>xq1</th>\n",
       "      <th>xq2</th>\n",
       "      <th>Td10</th>\n",
       "      <th>Td20</th>\n",
       "      <th>Tq10</th>\n",
       "      <th>Tq20</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>uid</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>GENROU_1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>None</td>\n",
       "      <td>900</td>\n",
       "      <td>20</td>\n",
       "      <td>60</td>\n",
       "      <td>0</td>\n",
       "      <td>...</td>\n",
       "      <td>1</td>\n",
       "      <td>1.8</td>\n",
       "      <td>0.3</td>\n",
       "      <td>0.25</td>\n",
       "      <td>0.55</td>\n",
       "      <td>0.25</td>\n",
       "      <td>8</td>\n",
       "      <td>0.03</td>\n",
       "      <td>0.4</td>\n",
       "      <td>0.05</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>2</td>\n",
       "      <td>1</td>\n",
       "      <td>GENROU_2</td>\n",
       "      <td>2</td>\n",
       "      <td>2</td>\n",
       "      <td>None</td>\n",
       "      <td>900</td>\n",
       "      <td>20</td>\n",
       "      <td>60</td>\n",
       "      <td>0</td>\n",
       "      <td>...</td>\n",
       "      <td>1</td>\n",
       "      <td>1.8</td>\n",
       "      <td>0.3</td>\n",
       "      <td>0.25</td>\n",
       "      <td>0.55</td>\n",
       "      <td>0.25</td>\n",
       "      <td>8</td>\n",
       "      <td>0.03</td>\n",
       "      <td>0.4</td>\n",
       "      <td>0.05</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>3</td>\n",
       "      <td>1</td>\n",
       "      <td>GENROU_3</td>\n",
       "      <td>3</td>\n",
       "      <td>3</td>\n",
       "      <td>None</td>\n",
       "      <td>900</td>\n",
       "      <td>20</td>\n",
       "      <td>60</td>\n",
       "      <td>0</td>\n",
       "      <td>...</td>\n",
       "      <td>1</td>\n",
       "      <td>1.8</td>\n",
       "      <td>0.3</td>\n",
       "      <td>0.25</td>\n",
       "      <td>0.55</td>\n",
       "      <td>0.25</td>\n",
       "      <td>8</td>\n",
       "      <td>0.03</td>\n",
       "      <td>0.4</td>\n",
       "      <td>0.05</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>4</td>\n",
       "      <td>1</td>\n",
       "      <td>GENROU_4</td>\n",
       "      <td>4</td>\n",
       "      <td>4</td>\n",
       "      <td>None</td>\n",
       "      <td>900</td>\n",
       "      <td>20</td>\n",
       "      <td>60</td>\n",
       "      <td>0</td>\n",
       "      <td>...</td>\n",
       "      <td>1</td>\n",
       "      <td>1.8</td>\n",
       "      <td>0.3</td>\n",
       "      <td>0.25</td>\n",
       "      <td>0.55</td>\n",
       "      <td>0.25</td>\n",
       "      <td>8</td>\n",
       "      <td>0.03</td>\n",
       "      <td>0.4</td>\n",
       "      <td>0.05</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>4 rows × 27 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "     idx  u      name  bus  gen   coi   Sn  Vn  fn  D  ...  S12   xd  xd1  \\\n",
       "uid                                                    ...                  \n",
       "0      1  1  GENROU_1    1    1  None  900  20  60  0  ...    1  1.8  0.3   \n",
       "1      2  1  GENROU_2    2    2  None  900  20  60  0  ...    1  1.8  0.3   \n",
       "2      3  1  GENROU_3    3    3  None  900  20  60  0  ...    1  1.8  0.3   \n",
       "3      4  1  GENROU_4    4    4  None  900  20  60  0  ...    1  1.8  0.3   \n",
       "\n",
       "      xd2   xq1   xq2  Td10  Td20  Tq10  Tq20  \n",
       "uid                                            \n",
       "0    0.25  0.55  0.25     8  0.03   0.4  0.05  \n",
       "1    0.25  0.55  0.25     8  0.03   0.4  0.05  \n",
       "2    0.25  0.55  0.25     8  0.03   0.4  0.05  \n",
       "3    0.25  0.55  0.25     8  0.03   0.4  0.05  \n",
       "\n",
       "[4 rows x 27 columns]"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "ss.GENROU.cache.df_in"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Parameters will be **converted** to system per-unit base after loading. To inspect the converted parameters, check the `cache.df` parameter."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>idx</th>\n",
       "      <th>u</th>\n",
       "      <th>name</th>\n",
       "      <th>bus</th>\n",
       "      <th>gen</th>\n",
       "      <th>coi</th>\n",
       "      <th>Sn</th>\n",
       "      <th>Vn</th>\n",
       "      <th>fn</th>\n",
       "      <th>D</th>\n",
       "      <th>M</th>\n",
       "      <th>ra</th>\n",
       "      <th>xl</th>\n",
       "      <th>xq</th>\n",
       "      <th>kp</th>\n",
       "      <th>kw</th>\n",
       "      <th>S10</th>\n",
       "      <th>S12</th>\n",
       "      <th>xd</th>\n",
       "      <th>xd1</th>\n",
       "      <th>xd2</th>\n",
       "      <th>xq1</th>\n",
       "      <th>xq2</th>\n",
       "      <th>Td10</th>\n",
       "      <th>Td20</th>\n",
       "      <th>Tq10</th>\n",
       "      <th>Tq20</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>uid</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>GENROU_1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>None</td>\n",
       "      <td>900</td>\n",
       "      <td>20</td>\n",
       "      <td>60</td>\n",
       "      <td>0</td>\n",
       "      <td>117.00</td>\n",
       "      <td>0</td>\n",
       "      <td>0.006667</td>\n",
       "      <td>0.188889</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0.2</td>\n",
       "      <td>0.033333</td>\n",
       "      <td>0.027778</td>\n",
       "      <td>0.061111</td>\n",
       "      <td>0.027778</td>\n",
       "      <td>8</td>\n",
       "      <td>0.03</td>\n",
       "      <td>0.4</td>\n",
       "      <td>0.05</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>2</td>\n",
       "      <td>1</td>\n",
       "      <td>GENROU_2</td>\n",
       "      <td>2</td>\n",
       "      <td>2</td>\n",
       "      <td>None</td>\n",
       "      <td>900</td>\n",
       "      <td>20</td>\n",
       "      <td>60</td>\n",
       "      <td>0</td>\n",
       "      <td>117.00</td>\n",
       "      <td>0</td>\n",
       "      <td>0.006667</td>\n",
       "      <td>0.188889</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0.2</td>\n",
       "      <td>0.033333</td>\n",
       "      <td>0.027778</td>\n",
       "      <td>0.061111</td>\n",
       "      <td>0.027778</td>\n",
       "      <td>8</td>\n",
       "      <td>0.03</td>\n",
       "      <td>0.4</td>\n",
       "      <td>0.05</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>3</td>\n",
       "      <td>1</td>\n",
       "      <td>GENROU_3</td>\n",
       "      <td>3</td>\n",
       "      <td>3</td>\n",
       "      <td>None</td>\n",
       "      <td>900</td>\n",
       "      <td>20</td>\n",
       "      <td>60</td>\n",
       "      <td>0</td>\n",
       "      <td>111.15</td>\n",
       "      <td>0</td>\n",
       "      <td>0.006667</td>\n",
       "      <td>0.188889</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0.2</td>\n",
       "      <td>0.033333</td>\n",
       "      <td>0.027778</td>\n",
       "      <td>0.061111</td>\n",
       "      <td>0.027778</td>\n",
       "      <td>8</td>\n",
       "      <td>0.03</td>\n",
       "      <td>0.4</td>\n",
       "      <td>0.05</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>4</td>\n",
       "      <td>1</td>\n",
       "      <td>GENROU_4</td>\n",
       "      <td>4</td>\n",
       "      <td>4</td>\n",
       "      <td>None</td>\n",
       "      <td>900</td>\n",
       "      <td>20</td>\n",
       "      <td>60</td>\n",
       "      <td>0</td>\n",
       "      <td>111.15</td>\n",
       "      <td>0</td>\n",
       "      <td>0.006667</td>\n",
       "      <td>0.188889</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0.2</td>\n",
       "      <td>0.033333</td>\n",
       "      <td>0.027778</td>\n",
       "      <td>0.061111</td>\n",
       "      <td>0.027778</td>\n",
       "      <td>8</td>\n",
       "      <td>0.03</td>\n",
       "      <td>0.4</td>\n",
       "      <td>0.05</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "     idx  u      name  bus  gen   coi   Sn  Vn  fn  D       M  ra        xl  \\\n",
       "uid                                                                           \n",
       "0      1  1  GENROU_1    1    1  None  900  20  60  0  117.00   0  0.006667   \n",
       "1      2  1  GENROU_2    2    2  None  900  20  60  0  117.00   0  0.006667   \n",
       "2      3  1  GENROU_3    3    3  None  900  20  60  0  111.15   0  0.006667   \n",
       "3      4  1  GENROU_4    4    4  None  900  20  60  0  111.15   0  0.006667   \n",
       "\n",
       "           xq  kp  kw  S10  S12   xd       xd1       xd2       xq1       xq2  \\\n",
       "uid                                                                            \n",
       "0    0.188889   0   0    0    1  0.2  0.033333  0.027778  0.061111  0.027778   \n",
       "1    0.188889   0   0    0    1  0.2  0.033333  0.027778  0.061111  0.027778   \n",
       "2    0.188889   0   0    0    1  0.2  0.033333  0.027778  0.061111  0.027778   \n",
       "3    0.188889   0   0    0    1  0.2  0.033333  0.027778  0.061111  0.027778   \n",
       "\n",
       "     Td10  Td20  Tq10  Tq20  \n",
       "uid                          \n",
       "0       8  0.03   0.4  0.05  \n",
       "1       8  0.03   0.4  0.05  \n",
       "2       8  0.03   0.4  0.05  \n",
       "3       8  0.03   0.4  0.05  "
      ]
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "ss.GENROU.cache.df"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
